package com.share.beta.factory.v1;

import com.share.beta.factory.PayService;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 构造方式注入  不需要注解
 * public PayFactory(List<PayService> list)
 */
@Component
public class PayFactoryV1 {
    private Map<String, PayService> map = new HashMap<>();

    //list会被自动注入
    public PayFactoryV1(List<PayService> list) {
        list.forEach(e -> map.put(e.getCode(), e));
    }

    public PayService getService(String code) {
        return map.get(code);
    }
}
